home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / layout / nsHTMLReflowMetrics.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  8KB  |  241 lines

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  26.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37. #ifndef nsHTMLReflowMetrics_h___
  38. #define nsHTMLReflowMetrics_h___
  39.  
  40. #include <stdio.h>
  41. #include "nsISupports.h"
  42. #include "nsMargin.h"
  43. #include "nsRect.h"
  44. // for MOZ_MATHML
  45. #include "nsIRenderingContext.h" //to get struct nsBoundingMetrics
  46.  
  47. //----------------------------------------------------------------------
  48.  
  49. // Option flags
  50. #define NS_REFLOW_CALC_MAX_WIDTH         0x0001
  51. #ifdef MOZ_MATHML
  52. #define NS_REFLOW_CALC_BOUNDING_METRICS  0x0002
  53. #endif
  54.  
  55. /**
  56.  * An nsCollapsingMargin represents a vertical collapsing margin between
  57.  * blocks as described in section 8.3.1 of CSS2,
  58.  * <URL: http://www.w3.org/TR/REC-CSS2/box.html#collapsing-margins >.
  59.  *
  60.  * All adjacent vertical margins collapse, and the resulting margin is
  61.  * the sum of the largest positive margin included and the smallest (most
  62.  * negative) negative margin included.
  63.  */
  64. struct nsCollapsingMargin {
  65.   private:
  66.     nscoord mMostPos;  // the largest positive margin included
  67.     nscoord mMostNeg;  // the smallest negative margin included
  68.  
  69.   public:
  70.     nsCollapsingMargin()
  71.         : mMostPos(0),
  72.           mMostNeg(0)
  73.       {
  74.       }
  75.  
  76.     nsCollapsingMargin(const nsCollapsingMargin& aOther)
  77.         : mMostPos(aOther.mMostPos),
  78.           mMostNeg(aOther.mMostNeg)
  79.       {
  80.       }
  81.  
  82.     PRBool operator==(const nsCollapsingMargin& aOther)
  83.       {
  84.         return mMostPos == aOther.mMostPos &&
  85.           mMostNeg == aOther.mMostNeg;
  86.       }
  87.  
  88.     PRBool operator!=(const nsCollapsingMargin& aOther)
  89.       {
  90.         return !(*this == aOther);
  91.       }
  92.  
  93.     nsCollapsingMargin& operator=(const nsCollapsingMargin& aOther)
  94.       {
  95.         mMostPos = aOther.mMostPos;
  96.         mMostNeg = aOther.mMostNeg;
  97.         return *this;
  98.       }
  99.  
  100.     void Include(nscoord aCoord)
  101.       {
  102.         if (aCoord > mMostPos)
  103.           mMostPos = aCoord;
  104.         else if (aCoord < mMostNeg)
  105.           mMostNeg = aCoord;
  106.       }
  107.  
  108.     void Include(const nsCollapsingMargin& aOther)
  109.       {
  110.         if (aOther.mMostPos > mMostPos)
  111.           mMostPos = aOther.mMostPos;
  112.         if (aOther.mMostNeg < mMostNeg)
  113.           mMostNeg = aOther.mMostNeg;
  114.       }
  115.  
  116.     void Zero()
  117.       {
  118.         mMostPos = 0;
  119.         mMostNeg = 0;
  120.       }
  121.  
  122.     PRBool IsZero() const
  123.       {
  124.         return (mMostPos == 0) && (mMostNeg == 0);
  125.       }
  126.  
  127.     nscoord get() const
  128.       {
  129.         return mMostPos + mMostNeg;
  130.       }
  131. };
  132.  
  133. /**
  134.  * Reflow metrics used to return the frame's desired size and alignment
  135.  * information.
  136.  *
  137.  * @see #Reflow()
  138.  */
  139. struct nsHTMLReflowMetrics {
  140.   nscoord width, height;        // [OUT] desired width and height
  141.   nscoord ascent, descent;      // [OUT] ascent and descent information
  142.  
  143.   nscoord mMaxElementWidth;     // [OUT]
  144.  
  145.   // Used for incremental reflow. If the NS_REFLOW_CALC_MAX_WIDTH flag is set,
  146.   // then the caller is requesting that you update and return your maximum width
  147.   nscoord mMaximumWidth;        // [OUT]
  148.  
  149. #ifdef MOZ_MATHML
  150.   // Metrics that _exactly_ enclose the text to allow precise MathML placements.
  151.   // If the NS_REFLOW_CALC_BOUNDING_METRICS flag is set, then the caller is 
  152.   // requesting that you also compute additional details about your inner
  153.   // bounding box and italic correction. For example, the bounding box of
  154.   // msup is the smallest rectangle that _exactly_ encloses both the text
  155.   // of the base and the text of the superscript.
  156.   nsBoundingMetrics mBoundingMetrics;  // [OUT]
  157. #endif
  158.  
  159.   // Carried out bottom margin values. This is the collapsed
  160.   // (generational) bottom margin value.
  161.   nsCollapsingMargin mCarriedOutBottomMargin;
  162.   
  163.   // For frames that have content that overflow their content area
  164.   // (NS_FRAME_OUTSIDE_CHILDREN) this rectangle represents the total area
  165.   // of the frame including visible overflow, i.e., don't include overflowing
  166.   // content that is hidden.
  167.   // The rect is in the local coordinate space of the frame, and should be at
  168.   // least as big as the desired size. If there is no content that overflows,
  169.   // then the overflow area is identical to the desired size and should be
  170.   // {0, 0, mWidth, mHeight}.
  171.   nsRect mOverflowArea;
  172.  
  173.   PRUint32 mFlags;
  174.  
  175.   // used by tables to optimize common cases
  176.   PRPackedBool mNothingChanged;
  177.  
  178.   // Should we compute mMaxElementWidth?
  179.   PRPackedBool mComputeMEW;
  180.  
  181.   nsHTMLReflowMetrics(PRBool aComputeMEW, PRUint32 aFlags = 0) {
  182.     mComputeMEW = aComputeMEW;
  183.     mMaxElementWidth = 0;
  184.     mMaximumWidth = 0;
  185.     mFlags = aFlags;
  186.     mOverflowArea.x = 0;
  187.     mOverflowArea.y = 0;
  188.     mOverflowArea.width = 0;
  189.     mOverflowArea.height = 0;
  190.     mNothingChanged = PR_FALSE;
  191. #ifdef MOZ_MATHML
  192.     mBoundingMetrics.Clear();
  193. #endif
  194.  
  195.     // XXX These are OUT parameters and so they shouldn't have to be
  196.     // initialized, but there are some bad frame classes that aren't
  197.     // properly setting them when returning from Reflow()...
  198.     width = height = 0;
  199.     ascent = descent = 0;
  200.   }
  201.  
  202.  /**
  203.   * set the maxElementWidth to the desired width. If the frame has a percent
  204.   * width specification it can be shrinked to 0 if the containing frame shrinks
  205.   * so we need to report 0 otherwise the incr. reflow will fail
  206.   * @param aWidthUnit - the width unit from the corresponding reflowstate
  207.   */
  208.   void SetMEWToActualWidth(nsStyleUnit aWidthUnit) {
  209.     if (aWidthUnit != eStyleUnit_Percent) {
  210.       mMaxElementWidth = width;
  211.     } else {
  212.       mMaxElementWidth = 0;
  213.     }
  214.   }
  215.  
  216.   nsHTMLReflowMetrics& operator=(const nsHTMLReflowMetrics& aOther)
  217.   {
  218.     mMaxElementWidth = aOther.mMaxElementWidth;
  219.     mMaximumWidth = aOther.mMaximumWidth;
  220.     mFlags = aOther.mFlags;
  221.     mCarriedOutBottomMargin = aOther.mCarriedOutBottomMargin;
  222.     mOverflowArea.x = aOther.mOverflowArea.x;
  223.     mOverflowArea.y = aOther.mOverflowArea.y;
  224.     mOverflowArea.width = aOther.mOverflowArea.width;
  225.     mOverflowArea.height = aOther.mOverflowArea.height;
  226.     mNothingChanged = aOther.mNothingChanged;
  227. #ifdef MOZ_MATHML
  228.     mBoundingMetrics = aOther.mBoundingMetrics;
  229. #endif
  230.  
  231.     width = aOther.width;
  232.     height = aOther.height;
  233.     ascent = aOther.ascent;
  234.     descent = aOther.descent;
  235.     return *this;
  236.   }
  237.  
  238. };
  239.  
  240. #endif /* nsHTMLReflowMetrics_h___ */
  241.